package com.stone.business.equipment.service;

/**
 * <pre>
 * 设备Service
 * </pre>
 */

import java.util.List;


import com.stone.business.equipment.pojo.TEquipmentBase;
import com.stone.business.equipment.pojo.TEquipmentParamByq;
import com.stone.business.equipment.pojo.TEquipmentParamByqBtqtjdq;
import com.stone.business.equipment.pojo.TEquipmentParamByqCyg;
import com.stone.business.equipment.pojo.TEquipmentParamByqFj;
import com.stone.business.equipment.pojo.TEquipmentParamByqLqq;
import com.stone.business.equipment.pojo.TEquipmentParamByqQyb;
import com.stone.business.equipment.pojo.TEquipmentParamByqTg;
import com.stone.business.equipment.pojo.TEquipmentParamByqTyzz;
import com.stone.business.equipment.pojo.TEquipmentParamByqYljdq;
import com.stone.business.equipment.pojo.TEquipmentParamByqYlsff;
import com.stone.business.equipment.pojo.TEquipmentParamByqYzjdq;
import com.stone.business.equipment.pojo.TEquipmentParamDkq;
import com.stone.business.equipment.pojo.TEquipmentParamDlhgq;
import com.stone.business.equipment.pojo.TEquipmentParamDlhgqRz;
import com.stone.business.equipment.pojo.TEquipmentParamDlq;
import com.stone.business.equipment.pojo.TEquipmentParamDrq;
import com.stone.business.equipment.pojo.TEquipmentParamDyhgq;
import com.stone.business.equipment.pojo.TEquipmentParamDyhgqRz;
import com.stone.business.equipment.pojo.TEquipmentParamGlkg;
import com.stone.business.equipment.pojo.TEquipmentParamKgg;
import com.stone.business.equipment.pojo.TEquipmentParamKyj;
import com.stone.business.equipment.pojo.TEquipmentParamMx;
import com.stone.business.equipment.pojo.TEquipmentParamQt;
import com.stone.business.equipment.pojo.TEquipmentParamSb;
import com.stone.business.equipment.pojo.TEquipmentParamXhxq;
import com.stone.business.equipment.pojo.TEquipmentParamZhdq;
import com.stone.sys.pojo.TBdzJg;

import frm.ssh.exception.AppException;
import frm.ssh.service.BaseService;

public class EquipmentCommonService extends BaseService {
	
	/**
	 * 保存
	 * @param ids
	 * @throws AppException
	 */
	public String saveEquip(List<Object> list) throws  AppException{
		
		String paraid = "";
		
		TEquipmentBase entity = (TEquipmentBase) list.get(0);

		// 新建
		if (entity.getId() == 0) {

			super.save(entity);

			// 开关柜
			if ("005".equals(entity.getSblx())) {	
				TEquipmentParamKgg paramKgg = (TEquipmentParamKgg) list.get(1);
				paramKgg.setBaseid(entity.getId());
				super.save(paramKgg);
				paraid = paramKgg.getId().toString();
				
				// 电流互感器
			} else  if ("006".equals(entity.getSblx())) {
				TEquipmentParamDlhgq paramDlhgq = (TEquipmentParamDlhgq) list.get(1);
				paramDlhgq.setBaseid(entity.getId());
				super.save(paramDlhgq);
				paraid = paramDlhgq.getId().toString();
					
				// 电压互感器
			} else  if ("007".equals(entity.getSblx())) {
				TEquipmentParamDyhgq paramDyhgq = (TEquipmentParamDyhgq) list.get(1);
				paramDyhgq.setBaseid(entity.getId());
				super.save(paramDyhgq);
				paraid = paramDyhgq.getId().toString();
					
				// 组合电器
			} else  if ("004".equals(entity.getSblx())) {
				TEquipmentParamZhdq paramZhdq = (TEquipmentParamZhdq) list.get(1);
				paramZhdq.setBaseid(entity.getId());
				super.save(paramZhdq);
				paraid = paramZhdq.getId().toString();
				
				// 隔离开关
			} else  if ("003".equals(entity.getSblx())) {
				TEquipmentParamGlkg paramGlkg = (TEquipmentParamGlkg) list.get(1);
				paramGlkg.setBaseid(entity.getId());
				super.save(paramGlkg);
				paraid = paramGlkg.getId().toString();
				
				// 断路器
			} else  if ("002".equals(entity.getSblx())) {
				TEquipmentParamDlq paramDlq = (TEquipmentParamDlq) list.get(1);
				paramDlq.setBaseid(entity.getId());
				super.save(paramDlq);
				paraid = paramDlq.getId().toString();
				
				// 变压器
			} else  if ("001".equals(entity.getSblx())) {
				TEquipmentParamByq paramByq = (TEquipmentParamByq) list.get(1);
				paramByq.setBaseid(entity.getId());
				super.save(paramByq);
				paraid = paramByq.getId().toString();
				
				// 所变
			} else  if ("021".equals(entity.getSblx())) {
			TEquipmentParamSb paramSb = (TEquipmentParamSb) list.get(1);
			paramSb.setBaseid(entity.getId());
			super.save(paramSb);
			paraid = paramSb.getId().toString();
				//  电容器
			} else  if ("019".equals(entity.getSblx())) {
			TEquipmentParamDrq paramDrq = (TEquipmentParamDrq) list.get(1);
			paramDrq.setBaseid(entity.getId());
			super.save(paramDrq);
			paraid = paramDrq.getId().toString();
	      	// 消弧线圈
			} else  if ("022".equals(entity.getSblx())) {
			TEquipmentParamXhxq paramXhxq = (TEquipmentParamXhxq) list.get(1);
			paramXhxq.setBaseid(entity.getId());
			super.save(paramXhxq);
			paraid = paramXhxq.getId().toString();
			// 母线
			} else  if ("023".equals(entity.getSblx())) {
			TEquipmentParamMx paramMx = (TEquipmentParamMx) list.get(1);
			paramMx.setBaseid(entity.getId());
			super.save(paramMx);
			paraid = paramMx.getId().toString();
			//  电抗器
			} else  if ("020".equals(entity.getSblx())) {
			TEquipmentParamDkq paramDkq = (TEquipmentParamDkq) list.get(1);
			paramDkq.setBaseid(entity.getId());
			super.save(paramDkq);
			paraid = paramDkq.getId().toString();
		//  空压机
			} else  if ("009".equals(entity.getSblx())) {
			TEquipmentParamKyj paramKyj = (TEquipmentParamKyj) list.get(1);
			paramKyj.setBaseid(entity.getId());
			super.save(paramKyj);
			paraid = paramKyj.getId().toString();
		//  其它
			} else  if ("008".equals(entity.getSblx())) {
			TEquipmentParamQt paramQt = (TEquipmentParamQt) list.get(1);
			paramQt.setBaseid(entity.getId());
			super.save(paramQt);
			paraid = paramQt.getId().toString();
	      
			// 二次设备
		}else  if (entity.getSblx().startsWith("E")) {
				paraid = "E";
			} 

			// 修改
		} else {
			
			if (entity.getModelid() <= 0) {

				super.update(entity);
				
				// 开关柜
				if ("005".equals(entity.getSblx())) {
					TEquipmentParamKgg paramKgg = (TEquipmentParamKgg) list.get(1);
					super.update(paramKgg);
					paraid = paramKgg.getId().toString();
					
					// 电流互感器
				} else if ("006".equals(entity.getSblx())) {
					TEquipmentParamDlhgq paramDlhgq = (TEquipmentParamDlhgq) list.get(1);
					super.update(paramDlhgq);
					paraid = paramDlhgq.getId().toString();
					
					// 电压互感器
				} else if ("007".equals(entity.getSblx())) {
					TEquipmentParamDyhgq paramDyhgq = (TEquipmentParamDyhgq) list.get(1);
					super.update(paramDyhgq);
					paraid = paramDyhgq.getId().toString();
					
					// 组合电器
				} else if ("004".equals(entity.getSblx())) {
					TEquipmentParamZhdq paramZhdq = (TEquipmentParamZhdq) list.get(1);
					super.update(paramZhdq);
					paraid = paramZhdq.getId().toString();
					
					// 隔离开关
				} else if ("003".equals(entity.getSblx())) {
					TEquipmentParamGlkg paramGlkg = (TEquipmentParamGlkg) list.get(1);
					super.update(paramGlkg);
					paraid = paramGlkg.getId().toString();
					
					// 断路器
				} else if ("002".equals(entity.getSblx())) {
					TEquipmentParamDlq paramDlq = (TEquipmentParamDlq) list.get(1);
					super.update(paramDlq);
					paraid = paramDlq.getId().toString();
					
					// 变压器
				} else if ("001".equals(entity.getSblx())) {
					TEquipmentParamByq paramByq = (TEquipmentParamByq) list.get(1);
					paramByq.setBaseid(entity.getId());
					super.update(paramByq);
					paraid = paramByq.getId().toString();
					
					
					// 所变
			} else  if ("021".equals(entity.getSblx())) {
				TEquipmentParamSb paramSb = (TEquipmentParamSb) list.get(1);
				paramSb.setBaseid(entity.getId());
				super.update(paramSb);
				paraid = paramSb.getId().toString();
					//  电容器
			} else  if ("019".equals(entity.getSblx())) {
			TEquipmentParamDrq paramDrq = (TEquipmentParamDrq) list.get(1);
			paramDrq.setBaseid(entity.getId());
			super.update(paramDrq);
			paraid = paramDrq.getId().toString();
	      	// 消弧线圈
			} else  if ("022".equals(entity.getSblx())) {
			TEquipmentParamXhxq paramXhxq = (TEquipmentParamXhxq) list.get(1);
			paramXhxq.setBaseid(entity.getId());
			super.update(paramXhxq);
			paraid = paramXhxq.getId().toString();
			// 母线
			} else  if ("023".equals(entity.getSblx())) {
			TEquipmentParamMx paramMx = (TEquipmentParamMx) list.get(1);
			paramMx.setBaseid(entity.getId());
			super.update(paramMx);
			paraid = paramMx.getId().toString();
			//  电抗器
			} else  if ("020".equals(entity.getSblx())) {
			TEquipmentParamDkq paramDkq = (TEquipmentParamDkq) list.get(1);
			paramDkq.setBaseid(entity.getId());
			super.update(paramDkq);
			paraid = paramDkq.getId().toString();
		//  空压机
			} else  if ("009".equals(entity.getSblx())) {
			TEquipmentParamKyj paramKyj = (TEquipmentParamKyj) list.get(1);
			paramKyj.setBaseid(entity.getId());
			super.update(paramKyj);
			paraid = paramKyj.getId().toString();
		//  其它设备
			} else  if ("008".equals(entity.getSblx())) {
			TEquipmentParamQt paramQt = (TEquipmentParamQt) list.get(1);
			paramQt.setBaseid(entity.getId());
			super.update(paramQt);
			paraid = paramQt.getId().toString();
				// 二次设备
			}else  if (entity.getSblx().startsWith("E")) {
					paraid = "E";
				} 
				
				
				// 参照新建
			} else {
				
				entity.setModelid(-entity.getModelid());
				super.save(entity);

				// 开关柜
				if ("005".equals(entity.getSblx())) {	
					TEquipmentParamKgg paramKgg = (TEquipmentParamKgg) list.get(1);
					paramKgg.setBaseid(entity.getId());
					super.save(paramKgg);
					paraid = paramKgg.getId().toString();
					
					// 电流互感器
				} else  if ("006".equals(entity.getSblx())) {
					TEquipmentParamDlhgq paramDlhgq = (TEquipmentParamDlhgq) list.get(1);
					paramDlhgq.setBaseid(entity.getId());
					super.save(paramDlhgq);
					paraid = paramDlhgq.getId().toString();
						
					// 电压互感器
				} else  if ("007".equals(entity.getSblx())) {
					TEquipmentParamDyhgq paramDyhgq = (TEquipmentParamDyhgq) list.get(1);
					paramDyhgq.setBaseid(entity.getId());
					super.save(paramDyhgq);
					paraid = paramDyhgq.getId().toString();
						
					// 组合电器
				} else  if ("004".equals(entity.getSblx())) {
					TEquipmentParamZhdq paramZhdq = (TEquipmentParamZhdq) list.get(1);
					paramZhdq.setBaseid(entity.getId());
					super.save(paramZhdq);
					paraid = paramZhdq.getId().toString();
					
					// 隔离开关
				} else  if ("003".equals(entity.getSblx())) {
					TEquipmentParamGlkg paramGlkg = (TEquipmentParamGlkg) list.get(1);
					paramGlkg.setBaseid(entity.getId());
					super.save(paramGlkg);
					paraid = paramGlkg.getId().toString();
					
					// 断路器
				} else  if ("002".equals(entity.getSblx())) {
					TEquipmentParamDlq paramDlq = (TEquipmentParamDlq) list.get(1);
					paramDlq.setBaseid(entity.getId());
					super.save(paramDlq);
					paraid = paramDlq.getId().toString();
					
					// 变压器
				} else  if ("001".equals(entity.getSblx())) {
					TEquipmentParamByq paramByq = (TEquipmentParamByq) list.get(1);
					paramByq.setBaseid(entity.getId());
					super.save(paramByq);
					paraid = paramByq.getId().toString();
					
				
					// 所变
			} else  if ("021".equals(entity.getSblx())) {
				TEquipmentParamSb paramSb = (TEquipmentParamSb) list.get(1);
				paramSb.setBaseid(entity.getId());
				super.save(paramSb);
				paraid = paramSb.getId().toString();
					//  电容器
			} else  if ("019".equals(entity.getSblx())) {
			TEquipmentParamDrq paramDrq = (TEquipmentParamDrq) list.get(1);
			paramDrq.setBaseid(entity.getId());
			super.save(paramDrq);
			paraid = paramDrq.getId().toString();
	      	// 消弧线圈
			} else  if ("022".equals(entity.getSblx())) {
			TEquipmentParamXhxq paramXhxq = (TEquipmentParamXhxq) list.get(1);
			paramXhxq.setBaseid(entity.getId());
			super.save(paramXhxq);
			paraid = paramXhxq.getId().toString();
			// 母线
			} else  if ("023".equals(entity.getSblx())) {
			TEquipmentParamMx paramMx = (TEquipmentParamMx) list.get(1);
			paramMx.setBaseid(entity.getId());
			super.save(paramMx);
			paraid = paramMx.getId().toString();
			//  电抗器
			} else  if ("020".equals(entity.getSblx())) {
			TEquipmentParamDkq paramDkq = (TEquipmentParamDkq) list.get(1);
			paramDkq.setBaseid(entity.getId());
			super.save(paramDkq);
			paraid = paramDkq.getId().toString();
		//  空压机
			} else  if ("009".equals(entity.getSblx())) {
			TEquipmentParamKyj paramKyj = (TEquipmentParamKyj) list.get(1);
			paramKyj.setBaseid(entity.getId());
			super.save(paramKyj);
			paraid = paramKyj.getId().toString();
		//  其它设备
			} else  if ("008".equals(entity.getSblx())) {
			TEquipmentParamQt paramQt = (TEquipmentParamQt) list.get(1);
			paramQt.setBaseid(entity.getId());
			super.save(paramQt);
			paraid = paramQt.getId().toString();
				// 二次设备
			} else  if (entity.getSblx().startsWith("E")) {
					paraid = "E";
				} 
			}
			
		}
		
		return paraid;

	}

	/**
	 * 删除
	 * @param ids
	 * @throws AppException
	 */
	public void deleteEquip(String ids) throws  AppException{
		
		
		// 查询出设备
		List<TEquipmentBase> rtn = super.findListByHql(" from TEquipmentBase where id in (" + ids + ")");
		
		// 根据设备类型删除子表信息
		for (TEquipmentBase e : rtn) {
			
			// 变压器
			if ("001".equals(e.getSblx())) {
				
				super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamByq.class.getName());
				super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamByqFj.class.getName());
				super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamByqLqq.class.getName());
				super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamByqCyg.class.getName());
				super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamByqYlsff.class.getName());
				super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamByqYzjdq.class.getName());
				super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamByqBtqtjdq.class.getName());
				super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamByqQyb.class.getName());
				super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamByqYljdq.class.getName());
				super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamByqTg.class.getName());
				super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamByqTyzz.class.getName());
				
				// 断路器
			} else if ("002".equals(e.getSblx())) {
				super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamDlq.class.getName());
				
				// 隔离开关
			} else if ("003".equals(e.getSblx())) {
				super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamGlkg.class.getName());
				
				// 组合电器
			} else if ("004".equals(e.getSblx())) {
				super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamZhdq.class.getName());
				
				// 开关柜
			} else if ("005".equals(e.getSblx())) {
				super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamKgg.class.getName());
				
				// 电流互感器
			} else if ("006".equals(e.getSblx())) {
				super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamDlhgq.class.getName());
				super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamDlhgqRz.class.getName());
				
				// 电压互感器
			} else if ("007".equals(e.getSblx())) {
				super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamDyhgq.class.getName());
				super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamDyhgqRz.class.getName());
				// 所变
		} else if ("021".equals(e.getSblx())) {
			super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamSb.class.getName());
				// 电容器
		} else if ("019".equals(e.getSblx())) {
			super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamDrq.class.getName());
				// 消弧线圈
		} else if ("022".equals(e.getSblx())) {
			super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamXhxq.class.getName());
		
				// 母线
		} else if ("023".equals(e.getSblx())) {
			super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamMx.class.getName());
		
			// 电抗器
		} else if ("020".equals(e.getSblx())) {
			super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamDkq.class.getName());
			// 空压机
		} else if ("009".equals(e.getSblx())) {
			super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamKyj.class.getName());
			// 其它设备
		} else if ("008".equals(e.getSblx())) {
			super.deleteByDHql("baseid in (" + ids + ")", null, TEquipmentParamQt.class.getName());
		}
			
			// 删除主表
			super.deleteAll(ids, TEquipmentBase.class.getName());

		}

	}
	
	/**
	 * 复制 将一个间隔下的设备复制到另一个间隔下
	 * @param fromId 复制的间隔id
	 * @param targetId 粘贴到的间隔id 
	 * @throws AppException
	 * @throws CloneNotSupportedException
	 */
	public void doCopyEquip(String fromId,String targetId) throws  AppException, CloneNotSupportedException{
		//查询出目标间隔
		TBdzJg tBdzJg=(TBdzJg)super.findById(Long.parseLong(targetId),TBdzJg.class.getName());		
		// 查询出屏柜
		List<TBdzJg> fromPgList = super.findListByHql(" from TBdzJg where parentid ='" + fromId + "'");
		for(TBdzJg fromPg:fromPgList){
			TBdzJg targetPg=(TBdzJg) fromPg.clone();
			targetPg.setParentid(tBdzJg.getId());
			targetPg.setBdzid(tBdzJg.getBdzid());
			targetPg.setDydj(tBdzJg.getDydj());
			targetPg.setId(Long.parseLong("0"));
			targetPg.setJgbh(tBdzJg.getJgbh());//把复制来的屏柜编号 改成目标间隔编号
			super.save(targetPg);
			//屏柜下的设备
			List<TEquipmentBase> rtn = super.findListByHql(" from TEquipmentBase where typeid ='" + fromPg.getId()+ "'");
			//复制屏柜下的设备
			doCopy_SavePara(targetPg,rtn);
		}
		// 查询出间隔下的设备
		List<TEquipmentBase> rtn = super.findListByHql(" from TEquipmentBase where typeid ='" + fromId + "'");
		//复制间隔下的设备
		doCopy_SavePara(tBdzJg,rtn);
	}	
	/**
	 * 将一个屏柜下的设备复制到另一个屏柜下
	 * @param fromId 源屏柜id
	 * @param targetId 目标屏柜id
	 * @throws CloneNotSupportedException
	 */
	public void doCopyPgToPg(String fromId,String targetId) throws CloneNotSupportedException{
		//查询出目标屏柜
		TBdzJg targetPg=(TBdzJg)super.findById(Long.parseLong(targetId),TBdzJg.class.getName());	
		//查询出源屏柜
		TBdzJg fromPg=(TBdzJg)super.findById(Long.parseLong(fromId),TBdzJg.class.getName());
		//屏柜下的设备
		List<TEquipmentBase> rtn = super.findListByHql(" from TEquipmentBase where typeid ='" + fromPg.getId()+ "'");
		//复制屏柜下的设备
		doCopy_SavePara(targetPg,rtn);
	}
	/**
	 * 将一个屏柜下的设备复制到另一个间隔下
	 * @param fromId 源屏柜id
	 * @param targetId 目标间隔id
	 * @throws CloneNotSupportedException
	 */
	public void doCopyPgToJg(String fromId,String targetId) throws CloneNotSupportedException{
		//查询出目标间隔
		TBdzJg targetJg=(TBdzJg)super.findById(Long.parseLong(targetId),TBdzJg.class.getName());	
		//查询出源屏柜
		TBdzJg fromPg=(TBdzJg)super.findById(Long.parseLong(fromId),TBdzJg.class.getName());
		//屏柜下的设备
		List<TEquipmentBase> rtn = super.findListByHql(" from TEquipmentBase where typeid ='" + fromPg.getId()+ "'");
		//复制屏柜下的设备
		doCopy_SavePara(targetJg,rtn);
	}	
	/**
	 * 将一个间隔下的设备复制到另一个屏柜下
	 * @param fromId 源间隔id
	 * @param targetId 目标屏柜id
	 * @throws CloneNotSupportedException
	 */
	@SuppressWarnings("unchecked")
	public void doCopyJgToPg(String fromId,String targetId) throws CloneNotSupportedException{
		//查询出源间隔
		TBdzJg fromJg=(TBdzJg)super.findById(Long.parseLong(fromId),TBdzJg.class.getName());	
		//查询出目标屏柜
		TBdzJg targetPg=(TBdzJg)super.findById(Long.parseLong(targetId),TBdzJg.class.getName());
		//源间隔下的设备
		List<TEquipmentBase> rtn = super.findListByHql(" from TEquipmentBase where state='2' and typeid ='" + fromJg.getId()+ "'");
		//复制屏柜下的设备
		doCopy_SavePara(targetPg,rtn);
	}	
	/**
	 * 将一个间隔下的设备复制到另一个间隔下by wangtao add20120428
	 * @param fromId 源间隔id
	 * @param targetId 目标屏柜id
	 * @throws CloneNotSupportedException
	 */
	@SuppressWarnings("unchecked")
	public void doCopySbToJg(String fromId,String targetId) throws CloneNotSupportedException{
		//查询出源间隔
		//TBdzJg fromJg=(TBdzJg)super.findById(Long.parseLong(fromId),TBdzJg.class.getName());	
		//查询出目标间隔
		TBdzJg targetJg=(TBdzJg)super.findById(Long.parseLong(targetId),TBdzJg.class.getName());
		//源间隔下的设备
		List<TEquipmentBase> rtn = super.findListByHql(" from TEquipmentBase where typeid ='" + fromId+ "'");
		//复制屏柜下的设备
		doCopy_SavePara(targetJg,rtn);
	}		
	/**
	 * 复制间隔设备方法doCopyEquip,调用的子方法
	 * 复制间隔或屏柜下的设备
	 * @param tBdzJg 间隔或屏柜
	 * @param rtn 设备List
	 * @throws CloneNotSupportedException
	 */
	public void doCopy_SavePara(TBdzJg tBdzJg,List<TEquipmentBase>  rtn) throws CloneNotSupportedException{
		// 循环设备
		for (TEquipmentBase e : rtn) {	
			//设置设备主表不一样的值
			TEquipmentBase backupEqui=e;
			TEquipmentBase tEqui=(TEquipmentBase) e.clone();//克隆，对象只改变id，hibernate是不允许的，他认为还是一个对象，应该对应一条记录，而这我们想再存一条记录 
			tEqui.setId(Long.parseLong("0"));
			tEqui.setBdzid(tBdzJg.getBdzid());//变电站id
			tEqui.setTypeid(tBdzJg.getId());//间隔id
			tEqui.setState(tBdzJg.getState());
			tEqui.setDydj(tBdzJg.getDydj());//电压等级
			  if(tEqui.getState().equals("1")){
					tEqui.setYxbh(tBdzJg.getJgbh());//运行编号
			  }
		
			// 复制主表
			super.save(tEqui);
			
			//设置设备对应的参数，牵涉很多表
			// 变压器
			if ("001".equals(e.getSblx())) {
				//1
				List<TEquipmentParamByq> tEquipmentParamByqList=super.findListByHql(" from TEquipmentParamByq where baseid ='"+backupEqui.getId()+"'");
				if(tEquipmentParamByqList!=null){
					for(TEquipmentParamByq eEquipmentParamByq:tEquipmentParamByqList){
						if(eEquipmentParamByq!=null){
							TEquipmentParamByq pojo=(TEquipmentParamByq) eEquipmentParamByq.clone();
							pojo.setBaseid(tEqui.getId());
							pojo.setId(Long.parseLong("0"));
							super.save(pojo);
						}
					}
				}
				//2
				List<TEquipmentParamByqFj> tEquipmentParamByqFjList=super.findListByHql(" from TEquipmentParamByqFj where baseid ='"+backupEqui.getId()+"'");
				if(tEquipmentParamByqFjList!=null){
					for(TEquipmentParamByqFj tEquipmentParamByqFj:tEquipmentParamByqFjList){
						if(tEquipmentParamByqFj!=null){
							TEquipmentParamByqFj pojo=(TEquipmentParamByqFj) tEquipmentParamByqFj.clone();
							pojo.setBaseid(tEqui.getId());
							pojo.setId(Long.parseLong("0"));
							super.save(pojo);
						}
					}
				}		
				//3
				List<TEquipmentParamByqLqq> tEquipmentParamByqLqqList=super.findListByHql(" from TEquipmentParamByqLqq where baseid ='"+backupEqui.getId()+"'");
				if(tEquipmentParamByqLqqList!=null){
					for(TEquipmentParamByqLqq tEquipmentParamByqLqq:tEquipmentParamByqLqqList){
						if(tEquipmentParamByqLqq!=null){
							TEquipmentParamByqLqq pojo=(TEquipmentParamByqLqq) tEquipmentParamByqLqq.clone();
							pojo.setBaseid(tEqui.getId());
							pojo.setId(Long.parseLong("0"));
							super.save(pojo);
						}
					}
				}			
				//4
				List<TEquipmentParamByqCyg> tEquipmentParamByqCygList=super.findListByHql(" from TEquipmentParamByqCyg where baseid ='"+backupEqui.getId()+"'");
				if(tEquipmentParamByqCygList!=null){
					for(TEquipmentParamByqCyg tEquipmentParamByqCyg:tEquipmentParamByqCygList){
						if(tEquipmentParamByqCyg!=null){
							TEquipmentParamByqCyg pojo=(TEquipmentParamByqCyg) tEquipmentParamByqCyg.clone();
							pojo.setBaseid(tEqui.getId());
							pojo.setId(Long.parseLong("0"));
							super.save(pojo);
						}
					}
				}		
				//5
				List<TEquipmentParamByqYlsff> tEquipmentParamByqYlsffList=super.findListByHql(" from TEquipmentParamByqYlsff where baseid ='"+backupEqui.getId()+"'");
				if(tEquipmentParamByqYlsffList!=null){
					for(TEquipmentParamByqYlsff tEquipmentParamByqYlsff:tEquipmentParamByqYlsffList){
						if(tEquipmentParamByqYlsff!=null){
							TEquipmentParamByqYlsff pojo=(TEquipmentParamByqYlsff)tEquipmentParamByqYlsff.clone();
							pojo.setBaseid(tEqui.getId());
							pojo.setId(Long.parseLong("0"));
							super.save(pojo);
						}
					}
				}		
				//6
				List<TEquipmentParamByqYzjdq> tEquipmentParamByqYzjdqList=super.findListByHql(" from TEquipmentParamByqYzjdq where baseid ='"+backupEqui.getId()+"'");
				if(tEquipmentParamByqYzjdqList!=null){
					for(TEquipmentParamByqYzjdq tEquipmentParamByqYzjdq:tEquipmentParamByqYzjdqList){
						if(tEquipmentParamByqYzjdq!=null){
							TEquipmentParamByqYzjdq pojo=(TEquipmentParamByqYzjdq)tEquipmentParamByqYzjdq.clone();
							pojo.setBaseid(tEqui.getId());
							pojo.setId(Long.parseLong("0"));
							super.save(pojo);
						}
					}
				}					
				//7
				List<TEquipmentParamByqBtqtjdq> tEquipmentParamByqBtqtjdqList=super.findListByHql(" from TEquipmentParamByqBtqtjdq where baseid ='"+backupEqui.getId()+"'");
				if(tEquipmentParamByqBtqtjdqList!=null){
					for(TEquipmentParamByqBtqtjdq tEquipmentParamByqBtqtjdq:tEquipmentParamByqBtqtjdqList){
						if(tEquipmentParamByqBtqtjdq!=null){
							TEquipmentParamByqBtqtjdq pojo=(TEquipmentParamByqBtqtjdq)tEquipmentParamByqBtqtjdq.clone();
							pojo.setBaseid(tEqui.getId());
							pojo.setId(Long.parseLong("0"));
							super.save(pojo);
						}
					}
				}		
				//8
				List<TEquipmentParamByqQyb> tEquipmentParamByqQybList=super.findListByHql(" from TEquipmentParamByqQyb where baseid ='"+backupEqui.getId()+"'");
				if(tEquipmentParamByqQybList!=null){
					for(TEquipmentParamByqQyb tEquipmentParamByqQyb:tEquipmentParamByqQybList){
						if(tEquipmentParamByqQyb!=null){
							TEquipmentParamByqQyb pojo=(TEquipmentParamByqQyb)tEquipmentParamByqQyb.clone();
							pojo.setBaseid(tEqui.getId());
							pojo.setId(Long.parseLong("0"));
							super.save(pojo);
						}
					}
				}			
				//9
				List<TEquipmentParamByqYljdq> tEquipmentParamByqYljdqList=super.findListByHql(" from TEquipmentParamByqYljdq where baseid ='"+backupEqui.getId()+"'");
				if(tEquipmentParamByqYljdqList!=null){
					for(TEquipmentParamByqYljdq tEquipmentParamByqYljdq:tEquipmentParamByqYljdqList){
						if(tEquipmentParamByqYljdq!=null){
							TEquipmentParamByqYljdq pojo=(TEquipmentParamByqYljdq)tEquipmentParamByqYljdq.clone();
							pojo.setBaseid(tEqui.getId());
							pojo.setId(Long.parseLong("0"));
							super.save(pojo);
						}
					}
				}			
				//10
				List<TEquipmentParamByqTg> tEquipmentParamByqTgList=super.findListByHql(" from TEquipmentParamByqTg where baseid ='"+backupEqui.getId()+"'");
				if(tEquipmentParamByqTgList!=null){
					for(TEquipmentParamByqTg tEquipmentParamByqTg:tEquipmentParamByqTgList){
						if(tEquipmentParamByqTg!=null){
							TEquipmentParamByqTg pojo=(TEquipmentParamByqTg)tEquipmentParamByqTg.clone();
							pojo.setBaseid(tEqui.getId());
							pojo.setId(Long.parseLong("0"));
							super.save(pojo);
						}
					}
				}		
				//11
				List<TEquipmentParamByqTyzz> tEquipmentParamByqTyzzList=super.findListByHql(" from TEquipmentParamByqTyzz where baseid ='"+backupEqui.getId()+"'");
				if(tEquipmentParamByqTyzzList!=null){
					for(TEquipmentParamByqTyzz tEquipmentParamByqTyzz:tEquipmentParamByqTyzzList){
						if(tEquipmentParamByqTyzz!=null){
							TEquipmentParamByqTyzz pojo=(TEquipmentParamByqTyzz)tEquipmentParamByqTyzz.clone();
							pojo.setBaseid(tEqui.getId());
							pojo.setId(Long.parseLong("0"));
							super.save(pojo);
						}
					}
				}							
				/*super.deleteByDHql("baseid in (" + fromId + ")", null, TEquipmentParamByq.class.getName());
				super.deleteByDHql("baseid in (" + fromId + ")", null, TEquipmentParamByqFj.class.getName());
				super.deleteByDHql("baseid in (" + fromId + ")", null, TEquipmentParamByqLqq.class.getName());
				super.deleteByDHql("baseid in (" + fromId + ")", null, TEquipmentParamByqCyg.class.getName());
				super.deleteByDHql("baseid in (" + fromId + ")", null, TEquipmentParamByqYlsff.class.getName());
				super.deleteByDHql("baseid in (" + fromId + ")", null, TEquipmentParamByqYzjdq.class.getName());
				super.deleteByDHql("baseid in (" + fromId + ")", null, TEquipmentParamByqBtqtjdq.class.getName());
				super.deleteByDHql("baseid in (" + fromId + ")", null, TEquipmentParamByqQyb.class.getName());
				super.deleteByDHql("baseid in (" + fromId + ")", null, TEquipmentParamByqYljdq.class.getName());
				super.deleteByDHql("baseid in (" + fromId + ")", null, TEquipmentParamByqTg.class.getName());
				super.deleteByDHql("baseid in (" + fromId + ")", null, TEquipmentParamByqTyzz.class.getName());*/
				
				// 断路器
			} else if ("002".equals(e.getSblx())) {
				//1
				List<TEquipmentParamDlq> tEquipmentParamDlqList=super.findListByHql(" from TEquipmentParamDlq where baseid ='"+backupEqui.getId()+"'");
				if(tEquipmentParamDlqList!=null){
					for(TEquipmentParamDlq tEquipmentParamDlq:tEquipmentParamDlqList){
						if(tEquipmentParamDlq!=null){
							TEquipmentParamDlq pojo=(TEquipmentParamDlq)tEquipmentParamDlq.clone();
							pojo.setBaseid(tEqui.getId());
							pojo.setId(Long.parseLong("0"));
							super.save(pojo);
						}
					}
				}		
				/*super.deleteByDHql("baseid in (" + fromId + ")", null, TEquipmentParamDlq.class.getName());*/
				
				// 隔离开关
			} else if ("003".equals(e.getSblx())) {
				//1
				List<TEquipmentParamGlkg> tEquipmentParamGlkgList=super.findListByHql(" from TEquipmentParamGlkg where baseid ='"+backupEqui.getId()+"'");
				if(tEquipmentParamGlkgList!=null){
					for(TEquipmentParamGlkg tEquipmentParamGlkg:tEquipmentParamGlkgList){
						if(tEquipmentParamGlkg!=null){
							TEquipmentParamGlkg pojo=(TEquipmentParamGlkg)tEquipmentParamGlkg.clone();
							pojo.setBaseid(tEqui.getId());
							pojo.setId(Long.parseLong("0"));
							super.save(pojo);
						}
					}
				}		
				/*super.deleteByDHql("baseid in (" + fromId + ")", null, TEquipmentParamGlkg.class.getName());*/
				
				// 组合电器
			} else if ("004".equals(e.getSblx())) {
				//1
				List<TEquipmentParamZhdq> tEquipmentParamZhdqList=super.findListByHql(" from TEquipmentParamZhdq where baseid ='"+backupEqui.getId()+"'");
				if(tEquipmentParamZhdqList!=null){
					for(TEquipmentParamZhdq tEquipmentParamZhdq:tEquipmentParamZhdqList){
						if(tEquipmentParamZhdq!=null){
							TEquipmentParamZhdq pojo=(TEquipmentParamZhdq)tEquipmentParamZhdq.clone();
							pojo.setBaseid(tEqui.getId());
							pojo.setId(Long.parseLong("0"));
							super.save(pojo);
						}
					}
				}						
				/*super.deleteByDHql("baseid in (" + fromId + ")", null, TEquipmentParamZhdq.class.getName());*/
				
				// 开关柜
			} else if ("005".equals(e.getSblx())) {
				//1
				List<TEquipmentParamKgg> tEquipmentParamKggList=super.findListByHql(" from TEquipmentParamKgg where baseid ='"+backupEqui.getId()+"'");
				if(tEquipmentParamKggList!=null){
					for(TEquipmentParamKgg tEquipmentParamKgg:tEquipmentParamKggList){
						if(tEquipmentParamKgg!=null){
							TEquipmentParamKgg pojo=(TEquipmentParamKgg)tEquipmentParamKgg.clone();
							pojo.setBaseid(tEqui.getId());
							pojo.setId(Long.parseLong("0"));
							super.save(pojo);
						}
					}
				}					
				/*super.deleteByDHql("baseid in (" + fromId + ")", null, TEquipmentParamKgg.class.getName());*/
				
				// 电流互感器
			} else if ("006".equals(e.getSblx())) {
				//1
				List<TEquipmentParamDlhgq> TEquipmentParamDlhgqList=super.findListByHql(" from TEquipmentParamDlhgq where baseid ='"+backupEqui.getId()+"'");
				if(TEquipmentParamDlhgqList!=null){
					for(TEquipmentParamDlhgq tEquipmentParamDlhgq:TEquipmentParamDlhgqList){
						if(tEquipmentParamDlhgq!=null){
							TEquipmentParamDlhgq pojo=(TEquipmentParamDlhgq)tEquipmentParamDlhgq.clone();
							pojo.setBaseid(tEqui.getId());
							pojo.setId(Long.parseLong("0"));
							super.save(pojo);
						}
					}
				}		
				//2
				List<TEquipmentParamDlhgqRz> tEquipmentParamDlhgqRzList=super.findListByHql(" from TEquipmentParamDlhgqRz where baseid ='"+backupEqui.getId()+"'");
				if(tEquipmentParamDlhgqRzList!=null){
					for(TEquipmentParamDlhgqRz tEquipmentParamDlhgqRz:tEquipmentParamDlhgqRzList){
						if(tEquipmentParamDlhgqRz!=null){
							TEquipmentParamDlhgqRz pojo=(TEquipmentParamDlhgqRz)tEquipmentParamDlhgqRz.clone();
							pojo.setBaseid(tEqui.getId());
							pojo.setId(Long.parseLong("0"));
							super.save(pojo);
						}
					}
				}						
				/*super.deleteByDHql("baseid in (" + fromId + ")", null, TEquipmentParamDlhgq.class.getName());
				super.deleteByDHql("baseid in (" + fromId + ")", null, TEquipmentParamDlhgqRz.class.getName());*/
				
				// 电压互感器
			} else if ("007".equals(e.getSblx())) {
				//1
				List<TEquipmentParamDyhgq> tEquipmentParamDyhgqList=super.findListByHql(" from TEquipmentParamDyhgq where baseid ='"+backupEqui.getId()+"'");
				if(tEquipmentParamDyhgqList!=null){
					for(TEquipmentParamDyhgq tEquipmentParamDyhgq:tEquipmentParamDyhgqList){
						if(tEquipmentParamDyhgq!=null){
							TEquipmentParamDyhgq pojo=(TEquipmentParamDyhgq)tEquipmentParamDyhgq.clone();
							pojo.setBaseid(tEqui.getId());
							pojo.setId(Long.parseLong("0"));
							super.save(pojo);
						}
					}
				}			
				//2
				List<TEquipmentParamDyhgqRz> tEquipmentParamDyhgqRzList=super.findListByHql(" from TEquipmentParamDyhgqRz where baseid ='"+backupEqui.getId()+"'");
				if(tEquipmentParamDyhgqRzList!=null){
					for(TEquipmentParamDyhgqRz tEquipmentParamDyhgqRz:tEquipmentParamDyhgqRzList){
						if(tEquipmentParamDyhgqRz!=null){
							TEquipmentParamDyhgqRz pojo=(TEquipmentParamDyhgqRz)tEquipmentParamDyhgqRz.clone();
							pojo.setBaseid(tEqui.getId());
							pojo.setId(Long.parseLong("0"));
							super.save(pojo);
						}
					}
				}					
			/*	super.deleteByDHql("baseid in (" + fromId + ")", null, TEquipmentParamDyhgq.class.getName());
				super.deleteByDHql("baseid in (" + fromId + ")", null, TEquipmentParamDyhgqRz.class.getName());*/
			}
			}
	}
}
